using System;
using System.Collections.Generic;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Caches;
using JetBrains.ReSharper.UnitTestExplorer;
using JetBrains.Util;

namespace JamesKovacs.ReSharper.UnitTestSupport.VstsUnit {
    public class VstsUnitTestFixtureElement : VstsUnitElementBase {
        private readonly string m_AssemblyLocation;

        public VstsUnitTestFixtureElement(IUnitTestProvider provider, IProject project, string typeName, string assemblyLocation) : base(provider, null, project, typeName) {
            m_AssemblyLocation = assemblyLocation;
        }

        public override IDeclaredElement GetDeclaredElement() {
            return PsiManager.GetInstance(GetSolution()).GetDeclarationsCache(DeclarationsCacheScope.ProjectScope(GetProject(), false), true).GetTypeElementByCLRName(GetTypeClrName());
        }

        public override string GetKind() {
            return "VSTS Test Class";
        }

        public override string GetTitle() {
            CLRTypeName clrTypeName = new CLRTypeName(GetTypeClrName());
            return clrTypeName.ShortName;
        }

        public override bool Matches(string filter) {
            return (GetTypeClrName().IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) != -1);
        }

        public string AssemblyLocation {
            get { return m_AssemblyLocation; }
        }

        public override IList<UnitTestTask> GetTaskSequence(IList<UnitTestElement> explicitElements) {
            return EmptyArray<UnitTestTask>.Instance;
        }
    }
}